package com.ctgu;

import java.util.Scanner;

public class test2 {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        int[] arr=new int[100];
        int a=scanner.nextInt();
        for(int i=0;i<a;i++)
            arr[i]=scanner.nextInt();
        System.out.println(maxSubArraySum(arr));
    }
    private static int maxSubArraySum(int[] arr) {
        int maxSum=arr[0];
        for (int i=1;i<arr.length;i++) {
            if (arr[i]+arr[i-1]>arr[i])
                arr[i]+=arr[i-1];
            maxSum=Math.max(maxSum,arr[i]);
        }
        return maxSum;
    }
}
